var t = getApp();

Page({
    data: {
        currentTab: 0,
        autoplay: !0,
        interval: 1500,
        duration: 500,
        vertical: !0,
        baseUrl: t.globalData.baseUrl,
        urlBase: t.globalData.urlBase
    },
    onLoad: function(t) {
        this.setData({
            orderId: t.orderid,
            isShare: t.isShare ? t.isShare : "false"
        }), this.getinitData();
    },
    getinitData: function() {
        var a = this, e = t.globalData.baseUrl + t.globalData.urlKanDetail;
        wx.request({
            url: e,
            data: {
                orderId: a.data.orderId,
                lng: t.globalData.lng,
                lat: t.globalData.lat
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var e = JSON.parse(t.data);
                if (console.log(e), 0 != e.code) wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 2e3
                }); else {
                    var r = [];
                    r = e.activity.imgs.split(","), a.setData({
                        store: e.store,
                        serverList: e.serverList,
                        activity: e.activity,
                        userKanList: e.activity.userKanList,
                        user: e.user,
                        startTime: e.activity.createTime,
                        lastTime: e.activity.lastTime,
                        shareImg: r,
                        lat: e.store.lat,
                        lng: e.store.lng,
                        name: e.store.name,
                        address: e.store.address,
                        activityId: e.activity.id
                    });
                    for (var i = 0, s = 0; s < e.activity.userKanList.length; s++) i = (parseFloat(e.activity.userKanList[s].price) + parseFloat(i)).toFixed(2);
                    a.setData({
                        userkanPrice: i,
                        userkanNum: e.activity.userKanList.length > 0 ? e.activity.userKanList.length : 0,
                        needKanPrice: parseFloat(e.activity.maxPrice - e.activity.minPrice - i).toFixed(2),
                        sumPrice: parseFloat(e.activity.maxPrice + e.activity.minPrice).toFixed(2),
                        curPrice: parseFloat(e.activity.maxPrice - i).toFixed(2)
                    }), a.test(a.data.startTime, a.data.lastTime);
                }
            },
            fail: function(t) {
                console.log(".....fail.....");
            }
        });
    },
    test: function(t, a) {
        var e = this, r = Date.parse(new Date(t.replace(/-/g, "/"))) / 1e3 + 60 * parseInt(a) * 60, i = setInterval(function() {
            var t = Date.parse(new Date()) / 1e3, a = r - t, s = "00", n = "00", o = "00";
            a > 0 && (o = a - 3600 * (s = Math.floor(a / 3600) < 10 ? "0" + Math.floor(a / 3600) : Math.floor(a / 3600)) - 60 * (n = Math.floor((a - 3600 * s) / 60) < 10 ? "0" + Math.floor((a - 3600 * s) / 60) : Math.floor((a - 3600 * s) / 60)) < 10 ? "0" + (a - 3600 * s - 60 * n) : a - 3600 * s - 60 * n), 
            e.setData({
                hours: s,
                minutes: n,
                seconds: o
            }), "00" == e.data.hours && "00" == e.data.minutes && "00" == e.data.seconds && clearInterval(i);
        }, 1e3);
    },
    openMap: function() {
        var t = this;
        wx.openLocation({
            latitude: parseFloat(t.data.lat),
            longitude: parseFloat(t.data.lng),
            name: t.data.name,
            address: t.data.address
        });
    },
    bindChange: function(t) {
        this.setData({
            currentTab: t.detail.current
        });
    },
    swichNav: function(t) {
        var a = this;
        if (this.data.currentTab === t.target.dataset.current) return !1;
        a.setData({
            currentTab: t.target.dataset.current
        });
    },
    serverDetail: function(t) {
        wx.navigateTo({
            url: "../index/detail?id=" + t.currentTarget.dataset.id + "&type=" + t.currentTarget.dataset.type
        });
    },
    kanDetail: function(t) {
        wx.navigateTo({
            url: "../activity/bargainDetails?id=" + t.currentTarget.dataset.id + "&type=" + t.currentTarget.dataset.type
        });
    },
    onShareAppMessage: function(t) {
        var a = this;
        return t.from, {
            title: "儿康小程序",
            path: "/pages/activity/bargainDetailsInvit?id=" + a.data.activityId + "&type=3&orderid=" + a.data.orderId + "&isShare=true",
            imageUrl: a.data.baseUrl + "download?id=" + a.data.shareImg[0],
            desc: "",
            success: function(t) {
                console.log("转发成功:" + JSON.stringify(t));
            },
            fail: function(t) {
                console.log("转发失败:" + JSON.stringify(t));
            }
        };
    },
    helpKan: function(a) {
        var e = this;
        wx.request({
            url: t.globalData.baseUrl + t.globalData.urlBtnKan,
            data: {
                orderId: e.data.orderId,
                userId: t.globalData.userId
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var a = JSON.parse(t.data);
                0 != a.code ? wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 2e3
                }) : wx.showToast({
                    title: "砍价成功您帮好友已砍" + a.msg,
                    icon: "none",
                    duration: 2e3
                });
            }
        });
    },
    groupaction: function(t) {
        var a = this;
        wx.navigateTo({
            url: "../activity/detail?id=" + t.currentTarget.dataset.id + "&type=" + t.currentTarget.dataset.type + "&orderid=" + a.data.orderId
        });
    }
});